package main

import (
	"fmt"
	"time"
)

//单向通道
func main() {
	ch1 := make(chan int)
	go pump(ch1)
	go suck(ch1)
	time.Sleep(time.Second * 200)
}

func suck(ch chan int) {
	for {
		fmt.Println(<-ch)
	}
}

func pump(ch chan int) {
	for i := 0; ; i++ {
		ch <- i
	}
}

// 定义一个只接收的方法
func counter(out chan<- int) {
	for i := 0; i < 10; i++ {
		out <- i
	}
	close(out)
}

// 定义一个只发送的方法 in <-chan int
func printer(in <-chan int) {
	for i := range in {
		fmt.Println(i)
	}
}
func squarer(out chan<- int, in <-chan int) {
	for i := range in {
		out <- i * i
	}
	close(out)
}
